import cv2
import numpy as np

#创建一张图片
# img = np.zeros((200, 200, 3), dtype=np.uint8)
# img[50:150,50:150] = 255  #设置图片中中间的区域为紫色

#非
# new_img = cv2.bitwise_not(img)
# cv2.imshow('new_img', new_img)

#与
img = np.zeros((200, 200, 3), dtype=np.uint8)
img2 = np.zeros((200, 200, 3), dtype=np.uint8)

img[20:120,20:120] = 255  #设置图片中中间的区域为紫色
img2[80:180,80:180] = 255  #设置图片中中间的区域为紫色

# 与
# new_img = cv2.bitwise_and(img,img2)

#或
# new_img = cv2.bitwise_or(img,img2)
#异或
new_img = cv2.bitwise_xor(img,img2)

cv2.imshow('img', img)
cv2.imshow('img2', img2)
cv2.imshow('new_img', new_img)
cv2.waitKey(0)